'''
Created on 2017年3月6日

@author: Administrator
'''
import re
print(re.match('www', 'www.runoob.com').span())  # 在起始位置匹配

print(re.match("com", "www.baidu.com",flags=1))
string = 'Cats are smarter than dogs'
print(re.search('dogs', string, re.M|re.I))

#字串匹配单词
line = "Cats are smarter than dogs"
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)
if matchObj:
   print ("matchObj.group() : ", matchObj.group())
   print ("matchObj.group(1) : ", matchObj.group(1))
   print ("matchObj.group(2) : ", matchObj.group(2))
else:
   print ("No match!!")

pattern='^\d[a-zA-Z]{1,3}'
string = '3deA2deA'
obj=re.match(pattern, string)
if obj:
    print("result:",obj.group())
else:
    print("no match!")